import request from '@/utils/request';
import { RoleTableListParams, RoleTableListItem, UpdateRolePermissionParam } from './roleData.d';



/**
 * 根据条件分页查询角色列表
 * @param params 查询条件
 */
export async function queryRole(params?: RoleTableListParams) {
    return request('/api/ums/role', {
        method: 'GET',
        params,
    });
}


/**
 * 新增角色
 * @param params /api/ums/roleTableListItem
 */
export async function addRole(params: RoleTableListItem) {
    return request('/api/ums/role', {
        method: 'POST',
        data: {
            ...params,
        },
    });
}

/**
 * 更新角色
 * @param params
 */
export async function updateRole(params: RoleTableListParams) {
    return request(`/api/ums/role/${params.roleId}`, {
        method: 'PUT',
        data: {
            ...params,
        },
    });
}
/**
 * 更新角色权限
 * @param params
 */
export async function updateRolePermissions(params: UpdateRolePermissionParam) {
    return request(`/api/ums/role/permissions/relation`, {
        method: 'POST',
        data: {
            ...params,
        },
    });
}


/**
 * 详情角色
 * @param params 主键
 */
export async function getRole(params:{ id: string|undefined }) {
    return request(`/api/ums/role/${params.id}`, {
        method: 'GET',
    });
}

/**
 * 删除角色
 * @param params 主键
 */
export async function removeRole(params: { id: string|undefined }) {
    return request(`/api/ums/role/${params.id}`, {
        method: 'DELETE',
        data: {
            ...params,
        },
    });
}

/**
 * 删除角色
 * @param params 主键数组
 */
export async function removeBatchRole(params: { ids: (string|undefined)[] }) {
    return request('/api/ums/role', {
        method: 'DELETE',
        data: {
            ...params,
        },
    });
}

/**
 * 详情角色
 * @param params 主键
 */
export async function getRolePermissionSelected(params:{ roleId: string }) {
    return request('/api/ums/role/permission/checkedItems', {
        method: 'GET',
        params,
    });
}
